package com.leinao.media.client;

/**
 * 连接选项
 *
 * @author zhangyu
 * @date 2021/12/2 14:00
 */
public class ClientOptions {
    private final Long readTimeOut;
    private final Long connectTimeOut;
    private final Long writeTimeOut;
    private final Integer maxIdleConnections;
    private final Long keepAliveDuration;

    public ClientOptions(ClientOptions.Builder builder) {
        this.readTimeOut = builder.readTimeOut;
        this.connectTimeOut = builder.connectTimeOut;
        this.writeTimeOut = builder.writeTimeOut;
        this.maxIdleConnections = builder.maxIdleConnections;
        this.keepAliveDuration = builder.keepAliveDuration;
    }

    public Long getReadTimeOut() {
        return this.readTimeOut;
    }

    public Long getConnectTimeOut() {
        return this.connectTimeOut;
    }

    public Long getWriteTimeOut() {
        return this.writeTimeOut;
    }

    public Integer getMaxIdleConnections() {
        return this.maxIdleConnections;
    }

    public Long getKeepAliveDuration() {
        return this.keepAliveDuration;
    }

    public static ClientOptions.Builder newBuilder() {
        return new ClientOptions.Builder();
    }

    public static final class Builder {
        private Long readTimeOut = 10000L;
        private Long connectTimeOut = 10000L;
        private Long writeTimeOut = 10000L;
        private Integer maxIdleConnections = 5;
        private Long keepAliveDuration = 10000L;

        public Builder() {
        }

        public ClientOptions.Builder readTimeOut(Long readTimeOut) {
            this.readTimeOut = readTimeOut;
            return this;
        }

        public ClientOptions.Builder connectTimeOut(Long connectTimeOut) {
            this.connectTimeOut = connectTimeOut;
            return this;
        }

        public ClientOptions.Builder writeTimeOut(Long writeTimeOut) {
            this.writeTimeOut = writeTimeOut;
            return this;
        }

        public ClientOptions.Builder maxIdleConnections(Integer maxIdleConnections) {
            this.maxIdleConnections = maxIdleConnections;
            return this;
        }

        public ClientOptions.Builder keepAliveDuration(Long keepAliveDuration) {
            this.keepAliveDuration = keepAliveDuration;
            return this;
        }

        public ClientOptions build() {
            return new ClientOptions(this);
        }
    }
}
